/*
 * Copyright (C) 2023 Coder.AN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include "udp.h"
#include <cstdlib>
#include <iostream>
#include <unistd.h>


int main(int argc, char* argv[])
{
    udp::UDPSender udp_sender;

    if (argc != 3)
    {
        std::cout << "usage: demo_udp_sender <ip> <port>" << std::endl;
        return 0;
    }

    udp_sender.set_target_ip(argv[1]);
    udp_sender.set_target_port(atoi(argv[2]));
    udp_sender.set_pack_size(4096);

    if (!udp_sender.init())
    {
        std::cout << "Can not init udp_sender!" << std::endl;
        return 0;
    }

    for (int i = 0; i < 10; i++)
    {
        udp_sender.send((uint8_t*)&i, sizeof(int));
        usleep(5 * 1000); // 暂停 5ms
    }

    return 0;
}